package com.dyz.LeetCodeforSwordFingerOffer;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * @author: daiyizheng
 * @date: 2021/7/8 22:12
 * @description:
 */
public class singleNumber56_II {
    public int singleNumber(int[] nums) {
        Map<Integer,Integer> map=new HashMap<>();
        for(int num:nums){
            if(map.containsKey(num)){
                map.put(num,map.get(num)+1);
            }else{
                map.put(num, 1);
            }
        }
        int [] ans=new int[2];
        int count=0;
        for(Map.Entry<Integer, Integer> entry:map.entrySet()){
            if(entry.getValue()==1){
                return entry.getKey();
            }
        }
        return -1;
    }
    public int singleNumber1(int[] nums) {
        int[] bitNums = new int[32];
        Arrays.fill(bitNums,0);
        for(int num:nums){
            int curBit = 1;
            for(int i = 31;i>=0;i--){
                if((curBit & num) == curBit){
                    bitNums[i]++;
                }
                curBit <<= 1;
            }
        }
        int result = 0;
        for(int i = 0;i<32; i++){
            result = result << 1;
            result += (bitNums[i]%3);
        }
        return result;
    }
}
